<!DOCTYPE html><html lang="en"><head><title>BillingPlanDelete.aspx</title></head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0"><meta name="groc-relative-root" content=""><meta name="groc-document-path" content="BillingPlanDelete.aspx"><meta name="groc-project-path" content="BillingPlanDelete.aspx.cs"><link rel="stylesheet" type="text/css" media="all" href="assets/style.css"><script type="text/javascript" src="assets/behavior.js"></script><body><div id="meta"><div class="file-path">BillingPlanDelete.aspx.cs</div></div><div id="document"><div class="segment"><div class="code"><div class="wrapper">﻿<span class="hljs-keyword">using</span> PayPal.Api;
<span class="hljs-keyword">using</span> System;
<span class="hljs-keyword">using</span> System.Collections.Generic;
<span class="hljs-keyword">using</span> System.Linq;
<span class="hljs-keyword">using</span> System.Web;
<span class="hljs-keyword">using</span> System.Web.UI;
<span class="hljs-keyword">using</span> System.Web.UI.WebControls;

namespace PayPal.Sample
{
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">partial</span> <span class="hljs-keyword">class</span> BillingPlanDelete : BaseSamplePage
    {
        <span class="hljs-keyword">protected</span> <span class="hljs-keyword">override</span> <span class="hljs-keyword">void</span> <span class="hljs-title">RunSample</span>()
        {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="api-context">Api Context</h3>
<p>Pass in a <code>APIContext</code> object to authenticate 
the call and to send a unique request id 
(that ensures idempotency). The SDK generates
a request id if you do not pass one explicitly. 
See <a href="/Source/Configuration.html">Configuration.cs</a> to know more about APIContext.</p></div></div><div class="code"><div class="wrapper">            <span class="hljs-keyword">var</span> apiContext = Configuration.GetAPIContext();</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="create-a-billing-plan">Create a Billing Plan</h3>
<p>For demonstration purposes, we&#39;ll first create a new billing plan.</p></div></div><div class="code"><div class="wrapper">            <span class="hljs-keyword">var</span> plan = <span class="hljs-keyword">new</span> Plan
            {
                name = <span class="hljs-string">"T-Shirt of the Month Club Plan"</span>,
                description = <span class="hljs-string">"Monthly plan for getting the t-shirt of the month."</span>,
                type = <span class="hljs-string">"fixed"</span>,
                merchant_preferences = <span class="hljs-keyword">new</span> MerchantPreferences
                {
                    setup_fee = <span class="hljs-keyword">new</span> Currency { <span class="hljs-keyword">value</span> = <span class="hljs-string">"1.00"</span>, currency = <span class="hljs-string">"USD"</span> },
                    return_url = <span class="hljs-string">"https://www.paypal.com"</span>,
                    cancel_url = <span class="hljs-string">"https://www.paypal.com"</span>,
                    auto_bill_amount = <span class="hljs-string">"YES"</span>,
                    initial_fail_amount_action = <span class="hljs-string">"CONTINUE"</span>,
                    max_fail_attempts = <span class="hljs-string">"0"</span>
                },
                payment_definitions = <span class="hljs-keyword">new</span> List&lt;PaymentDefinition&gt;
                {
                    <span class="hljs-keyword">new</span> PaymentDefinition()
                    {
                        name = <span class="hljs-string">"Standard Plan"</span>,
                        type = <span class="hljs-string">"REGULAR"</span>,
                        frequency = <span class="hljs-string">"MONTH"</span>,
                        frequency_interval = <span class="hljs-string">"1"</span>,
                        amount = <span class="hljs-keyword">new</span> Currency() { <span class="hljs-keyword">value</span> = <span class="hljs-string">"19.99"</span>, currency = <span class="hljs-string">"USD"</span> },
                        cycles = <span class="hljs-string">"11"</span>,
                        charge_models = <span class="hljs-keyword">new</span> List&lt;ChargeModel&gt;
                        {
                            <span class="hljs-keyword">new</span> ChargeModel
                            {
                                type = <span class="hljs-string">"TAX"</span>,
                                amount = <span class="hljs-keyword">new</span> Currency() { <span class="hljs-keyword">value</span> = <span class="hljs-string">"2.47"</span>, currency = <span class="hljs-string">"USD"</span> }
                            },
                            <span class="hljs-keyword">new</span> ChargeModel()
                            {
                                type = <span class="hljs-string">"SHIPPING"</span>,
                                amount = <span class="hljs-keyword">new</span> Currency() { <span class="hljs-keyword">value</span> = <span class="hljs-string">"9.99"</span>, currency = <span class="hljs-string">"USD"</span> }
                            }
                        }
                    }
                }
            };

            <span class="hljs-preprocessor">#<span class="hljs-keyword">region</span> Track Workflow</span>
            <span class="hljs-comment">//--------------------</span>
            <span class="hljs-keyword">this</span>.flow.AddNewRequest(<span class="hljs-string">"Create the billing plan"</span>, plan);
            <span class="hljs-comment">//--------------------</span>
            <span class="hljs-preprocessor">#<span class="hljs-keyword">endregion</span></span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Create the billing plan.</p></div></div><div class="code"><div class="wrapper">            <span class="hljs-keyword">var</span> createdPlan = plan.Create(apiContext);

            <span class="hljs-preprocessor">#<span class="hljs-keyword">region</span> Track Workflow</span>
            <span class="hljs-comment">//--------------------</span>
            <span class="hljs-keyword">this</span>.flow.RecordResponse(createdPlan);
            <span class="hljs-comment">//--------------------</span>
            <span class="hljs-preprocessor">#<span class="hljs-keyword">endregion</span></span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="delete-the-billing-plan">Delete the Billing Plan</h3>
<p>Deleting the plan is done by applying an update to the plan with its <code>state</code> set to <code>DELETED</code>.</p>
<blockquote>
<p>NOTE: Only the &#39;replace&#39; operation is supported when updating billing plans.
For demonstration purposes, we&#39;ll create the <code>patchRequest</code> object here to show you how the plan is being deleted.</p>
</blockquote></div></div><div class="code"><div class="wrapper">            <span class="hljs-keyword">var</span> patchRequest = <span class="hljs-keyword">new</span> PatchRequest
            {
                <span class="hljs-keyword">new</span> Patch
                {
                    op = <span class="hljs-string">"replace"</span>,
                    path = <span class="hljs-string">"/"</span>,
                    <span class="hljs-keyword">value</span> = <span class="hljs-keyword">new</span> Plan { state = <span class="hljs-string">"DELETED"</span> }
                }
            };

            <span class="hljs-preprocessor">#<span class="hljs-keyword">region</span> Track Workflow</span>
            <span class="hljs-keyword">this</span>.flow.AddNewRequest(<span class="hljs-string">"Delete the billing plan"</span>, patchRequest);
            <span class="hljs-preprocessor">#<span class="hljs-keyword">endregion</span></span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>To make it easier for developers, this functionality has been built into the <code>Plan.Delete()</code> method.</p></div></div><div class="code"><div class="wrapper">            createdPlan.Delete(apiContext);

            <span class="hljs-preprocessor">#<span class="hljs-keyword">region</span> Track Workflow</span>
            <span class="hljs-keyword">this</span>.flow.RecordActionSuccess(<span class="hljs-string">"Billing plan deleted successfully"</span>);
            <span class="hljs-preprocessor">#<span class="hljs-keyword">endregion</span></span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>For more information, please visit <a href="https://developer.paypal.com/docs/api/">PayPal Developer REST API Reference</a>.</p></div></div><div class="code"><div class="wrapper">        }
    }
}</div></div></div></div></body></html>